package cn.dapeng.linked;

/**
 * 单链表实现栈
 *
 * @param <V>
 */
public class MyStack<V> {

    private Node<V> head;

    private int size;


    public MyStack() {
        head = null;
        size = 0;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public int size() {
        return size;
    }

    public void push(V v) {
        Node<V> cur = new Node(v);
        if (head == null) {
            head = cur;
        } else {
            cur.next = head;
            head = cur;
        }
        size++;
    }

    public V pop() {
        V v = null;
        if (head != null) {
            v = head.value;
            head = head.next;
            size--;
        }
        return v;
    }

    public static class Node<V> {
        public V value;

        public Node<V> next;

        public Node(V v) {
            this.value = v;
        }
    }
}
